<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>x-admin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/xadmin/lib/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <!--主体内容 start-->
        <div class="layui-row">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this" id="user_id">会员发布</li>
                    <li id="admin_id">管理员发布</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-row" >

                            <div class="layui-col-md3">
                                <input type="text" id="ser_row" name="ser_row" required  lay-verify="required" placeholder="标题或者发布人员" autocomplete="off" class="layui-input">
                            </div>

                            <div class="layui-col-md1">
                                <button style="margin-left: 50px;" class="layui-btn" onclick="ser_on()">搜索</button>
                            </div>
                        </div>
                        <table id="demo" lay-filter="test">

                        </table>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row" >

                        <div class="layui-col-md3">
                            <input type="text" id="ser_row2" name="ser_row" required  lay-verify="required" placeholder="标题或者发布人员" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-col-md1">
                            <button style="margin-left: 50px;" class="layui-btn" onclick="ser_on2()">搜索</button>
                        </div>
                            <div class="layui-col-md1">
                            <button style="margin-left: 50px;" class="layui-btn layui-btn-normal" onclick="add()">发布文章</button>
                        </div>
                    </div>
                        <table id="demo2" lay-filter="test">

                        </table></div>
                </div>
            </div>
        </div>



        <!--主体内容 end-->
    </div>
</div>

<script src="/static/xadmin/lib/layui/jquery-3.2.1.min.js"></script>
<script src="/static/xadmin/lib/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/xadmin/' //静态资源所在路径
    });
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
    });
    layui.use('table', function(){
        var table = layui.table;
        var urls = '{:url("admin/article/index")}'+'?type='+1;
        //第一个实例
        TB = table.render({
            elem: '#demo'
            ,height: 'full-170'
            ,limits:[100,500]
            ,limit:100
            ,url: urls //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID',  sort: true}
                ,{field: 'user_name', title: '发布人员',  sort: true}
                ,{field: 'title', title: '文章标题',  sort: true,templet:function (d) {
                    return '<div onmouseover="show_shopm(this,\''+d.remark+'\')">'+d.title+'</div>';
                }}
                ,{field: 'view', title: '浏览数',  sort: true}
                ,{field: 'like', title: '点赞数',  sort: true}
                ,{field: 'is_reprint', title: '文章属性', sort: true,templet: function(d) {
                    if(d.is_reprint == 1) {
                        return '原创';
                    } else if(d.is_reprint == 2) {
                        return '转载';
                    }
                }}
                ,{field: 'release_time', title: '发布时间',  sort: true}
                ,{field: 'status', title: '发布状态', sort: true,templet: function(d) {
                    if(d.status == 1) {
                        return '已发布';
                    } else if(d.status == 2) {
                        return '草稿箱';
                    }
                }}
                ,{field: 'up_shelf', title: '上下架', sort: true,templet: function(d) {
                    if(d.up_shelf == 1) {
                        return '<span style="color: #1E9FFF">已上架</span>';
                    } else if(d.up_shelf == 2) {
                        return '<span style="color: red">已下架</span>';
                    }
                }}
                ,{field: 'sort', title: '排序',  sort: true}
                ,{field: 'create_time', title: '创建时间',  sort: true}
                ,{field: '#', title: '操作',toolbar: '#barDemo'}
            ]]
        });
    });
    //搜索
    function ser_on(){
        var ser_row = $("#ser_row").val();
        var urls = '{:url("admin/article/index")}'+'?keyword='+ser_row+'&type='+1;
        TB.reload({
            url: urls
            ,cols: [[ //表头
                {field: 'id', title: 'ID',  sort: true}
                ,{field: 'user_name', title: '发布人员',  sort: true}
                ,{field: 'title', title: '文章标题',  sort: true,templet:function (d) {
                    return '<div onmouseover="show_shopm(this,\''+d.remark+'\')">'+d.title+'</div>';
                }}
                ,{field: 'view', title: '浏览数',  sort: true}
                ,{field: 'like', title: '点赞数',  sort: true}
                ,{field: 'is_reprint', title: '文章属性', sort: true,templet: function(d) {
                    if(d.is_reprint == 1) {
                        return '原创';
                    } else if(d.is_reprint == 2) {
                        return '转载';
                    }
                }}
                ,{field: 'release_time', title: '发布时间',  sort: true}
                ,{field: 'status', title: '发布状态', sort: true,templet: function(d) {
                    if(d.status == 1) {
                        return '已发布';
                    } else if(d.status == 2) {
                        return '草稿箱';
                    }
                }}
                ,{field: 'up_shelf', title: '上下架', sort: true,templet: function(d) {
                    if(d.up_shelf == 1) {
                        return '<span style="color: #1E9FFF">已上架</span>';
                    } else if(d.up_shelf == 2) {
                        return '<span style="color: red">已下架</span>';
                    }
                }}
                ,{field: 'sort', title: '排序',  sort: true}
                ,{field: 'create_time', title: '创建时间',  sort: true}
                ,{field: '#', title: '操作',toolbar: '#barDemo'}
            ]]
        });
    }

    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        $('#user_id').on('click', function(){
            //会员发布
            layui.use('table', function(){
                var table = layui.table;
                var urls = '{:url("admin/article/index")}'+'?type='+1;
                //第一个实例
                TB = table.render({
                    elem: '#demo'
                    ,height: 'full-170'
                    ,limits:[100,500]
                    ,limit:100
                    ,url: urls //数据接口
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {field: 'id', title: 'ID',  sort: true}
                        ,{field: 'user_name', title: '发布人员',  sort: true}
                        ,{field: 'title', title: '文章标题',  sort: true,templet:function (d) {
                            return '<div onmouseover="show_shopm(this,\''+d.remark+'\')">'+d.title+'</div>';
                        }}
                        ,{field: 'view', title: '浏览数',  sort: true}
                        ,{field: 'like', title: '点赞数',  sort: true}
                        ,{field: 'is_reprint', title: '文章属性', sort: true,templet: function(d) {
                            if(d.is_reprint == 1) {
                                return '原创';
                            } else if(d.is_reprint == 2) {
                                return '转载';
                            }
                        }}
                        ,{field: 'release_time', title: '发布时间',  sort: true}
                        ,{field: 'status', title: '发布状态', sort: true,templet: function(d) {
                            if(d.status == 1) {
                                return '已发布';
                            } else if(d.status == 2) {
                                return '草稿箱';
                            }
                        }}
                        ,{field: 'up_shelf', title: '上下架', sort: true,templet: function(d) {
                            if(d.up_shelf == 1) {
                                return '<span style="color: #1E9FFF">已上架</span>';
                            } else if(d.up_shelf == 2) {
                                return '<span style="color: red">已下架</span>';
                            }
                        }}
                        ,{field: 'sort', title: '排序',  sort: true}
                        ,{field: 'create_time', title: '创建时间',  sort: true}
                        ,{field: '#', title: '操作',toolbar: '#barDemo'}
                    ]]
                });
            });
        });
        $('#admin_id').on('click', function(){
            //管理发布
            layui.use('table', function(){
                var table = layui.table;
                var urls = '{:url("admin/article/index")}'+'?type='+2;
                //第一个实例
                TB = table.render({
                    elem: '#demo2'
                    ,height: 'full-170'
                    ,limits:[100,500]
                    ,limit:100
                    ,url: urls //数据接口
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {field: 'id', title: 'ID',  sort: true}
                        ,{field: 'names', title: '发布人员',  sort: true}
                        ,{field: 'title', title: '文章标题',  sort: true,templet:function (d) {
                            return '<div onmouseover="show_shopm(this,\''+d.remark+'\')">'+d.title+'</div>';
                        }}
                        ,{field: 'view', title: '浏览数',  sort: true}
                        ,{field: 'like', title: '点赞数',  sort: true}
                        ,{field: 'is_reprint', title: '文章属性', sort: true,templet: function(d) {
                            if(d.is_reprint == 1) {
                                return '原创';
                            } else if(d.is_reprint == 2) {
                                return '转载';
                            }
                        }}
                        ,{field: 'release_time', title: '发布时间',  sort: true}
                        ,{field: 'status', title: '发布状态', sort: true,templet: function(d) {
                            if(d.status == 1) {
                                return '已发布';
                            } else if(d.status == 2) {
                                return '草稿箱';
                            }
                        }}
                        ,{field: 'up_shelf', title: '上下架', sort: true,templet: function(d) {
                            if(d.up_shelf == 1) {
                                return '<span style="color: #1E9FFF">已上架</span>';
                            } else if(d.up_shelf == 2) {
                                return '<span style="color: red">已下架</span>';
                            }
                        }}
                        ,{field: 'sort', title: '排序',  sort: true}
                        ,{field: 'create_time', title: '创建时间',  sort: true}
                        ,{field: '#', title: '操作',toolbar: '#barDemo'}
                    ]]
                });
            });
        });

    });

    //搜索
    function ser_on2(){
        var ser_row = $("#ser_row2").val();
        var urls = '{:url("admin/article/index")}'+'?keyword2='+ser_row+'&type='+2;
        TB.reload({
            url: urls
            ,cols: [[ //表头
                {field: 'id', title: 'ID',  sort: true}
                ,{field: 'names', title: '发布人员',  sort: true}
                ,{field: 'title', title: '文章标题',  sort: true,templet:function (d) {
                    return '<div onmouseover="show_shopm(this,\''+d.remark+'\')">'+d.title+'</div>';
                }}
                ,{field: 'view', title: '浏览数',  sort: true}
                ,{field: 'like', title: '点赞数',  sort: true}
                ,{field: 'is_reprint', title: '文章属性', sort: true,templet: function(d) {
                    if(d.is_reprint == 1) {
                        return '原创';
                    } else if(d.is_reprint == 2) {
                        return '转载';
                    }
                }}
                ,{field: 'release_time', title: '发布时间',  sort: true}
                ,{field: 'status', title: '发布状态', sort: true,templet: function(d) {
                    if(d.status == 1) {
                        return '已发布';
                    } else if(d.status == 2) {
                        return '草稿箱';
                    }
                }}
                ,{field: 'up_shelf', title: '上下架', sort: true,templet: function(d) {
                    if(d.up_shelf == 1) {
                        return '<span style="color: #1E9FFF">已上架</span>';
                    } else if(d.up_shelf == 2) {
                        return '<span style="color: red">已下架</span>';
                    }
                }}
                ,{field: 'sort', title: '排序',  sort: true}
                ,{field: 'create_time', title: '创建时间',  sort: true}
                ,{field: '#', title: '操作',toolbar: '#barDemo'}
            ]]
        });
    }

    /*
    文章说明显示
     */
    function show_shopm(t,row){
        //小tips
        layer.tips(row,t, {
            tips: [1, '#3595CC'],
            time: 4000
        });
    }
    /*
    添加
     */
    function add() {
        var url='{:url("admin/article/add")}';
        layer.open({
            type: 2,
            title: '信息',
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: url, //iframe的url
        });
    }
    /*
    编辑
     */
    function set_edit(t) {
        var id=$(t).attr("id-data");
        var url='{:url("admin/article/edit")}'+'?id='+id;
        layer.open({
            type: 2,
            title: '信息',
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: url, //iframe的url
        });
    }

    /*
    删除 上下架
     */
    function set_del_x(t) {
        var id=$(t).attr("id-data");
        var up_shelf=2;
        layer.confirm('你确定要下架么？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function(index, layero){
            //按钮【按钮一】的回调
            $.post('{:url("admin/article/del")}',{'id':id,'up_shelf':up_shelf},function(data){
                if(data.code==1){
                    layer.msg(data.msg,{icon:1});
                    setTimeout(function () {
                        location.reload();
                    },1500);

                }else{
                    layer.alert(data.msg,{icon:2});
                }
            });

        }, function(index){
            //按钮【按钮二】的回调
        });
    }


    function set_del_s(t) {
        var id=$(t).attr("id-data");
        var up_shelf=1;
        layer.confirm('你确定要上架么？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function(index, layero){
            //按钮【按钮一】的回调
            $.post('{:url("admin/article/del")}',{'id':id,'up_shelf':up_shelf},function(data){
                if(data.code==1){
                    layer.msg(data.msg,{icon:1});
                    setTimeout(function () {
                        location.reload();
                    },1500);

                }else{
                    layer.alert(data.msg,{icon:2});
                }
            });

        }, function(index){
            //按钮【按钮二】的回调
        });
    }

</script>
</body>
</html>

<script type="text/html" id="barDemo">
    {{#  if(d.up_shelf == 1){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs "  id-data="{{d.id}}" onclick="set_del_x(this)">下架</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-danger layui-btn-xs "  id-data="{{d.id}}" onclick="set_del_s(this)">上架</a>
    {{#  } }}
    <a class="layui-btn layui-btn-xs" lay-event="detail"  id-data="{{d.id}}" onclick="set_edit(this)">修改</a>

</script>
<!--
<script type="text/html" id="titleTpl">
    {{#  if(d.up_shelf == 1){ }}
    &lt;!&ndash;<span style="color:green">上架</span>&ndash;&gt;
    <div class="layui-form-item"><input type="checkbox"  lay-filter="switchTest" data-id="{{d.id}}" checked="" name="switch" lay-skin="switch" lay-text="ON|OFF"></div>
    {{#  } else { }}
    &lt;!&ndash;<span style="color: red;">下架</span>&ndash;&gt;
    <div class="layui-form-item"><input type="checkbox"  lay-filter="switchTest" data-id="{{d.id}}"  name="switch" lay-skin="switch" lay-text="ON|OFF"></div>
    {{#  } }}
</script>-->
